
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">

    <title>班级说说</title>

    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/css/jumbotron.css" rel="stylesheet">
    <style type="text/css">
        body{
            padding-top:    120px;
        }
        #wrong-alert{
            display: none;
        }
    </style>


</head>

<body>
<%include header.ejs%>
<div class="container">
    <!-- Example row of columns -->
    <div class="row">
        <h1>欢迎注册</h1>
        <form role="form">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" class="form-control" name="username" id="username" placeholder="用户名">
            </div>
            <div class="form-group">
                <label for="psd">密码</label>
                <input type="password" class="form-control" name="psd" id="psd" placeholder="密码">
            </div>
      <!--      <div class="form-group">
                <label for="exampleInputFile">File input</label>
                <input type="file" id="exampleInputFile">
                <p class="help-block">Example block-level help text here.</p>
            </div>-->
            <div class="checkbox">
                <label>
                    <input type="checkbox">自愿遵守法律法规
                </label>
            </div>
            <button type="button" class="btn btn-default" id="submit">提交</button>
        </form>
        <div class="alert alert-danger" role="alert" id="wrong-alert">
            用户名被占用
        </div>
    </div>

</div> <!-- /container -->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/js/jquery-1.11.3.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script type="text/javascript">
    $("input").focus(function () {
        $("#wrong-alert").fadeOut();
    })
   $("#submit").click(function () {
       $.post('/doregister',{
           "username":$("#username").val(),
           "psd":$("#psd").val()
       }, function (result) {
           if(result==1){
                alert("注册成功了,将自动跳转到首页");
               window.location="/";
           }else if(result=-1){
               $("#wrong-alert").fadeIn();
               $("#wrong-alert").html("用户名被占用了");
           }else if(result=-3){
                //服务器错误
           }
       })
   })
</script>
</body>
</html>
